package com.ymatou.iapi.optrade.testcase;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.optrade.parameter.enums.CancelOrderTypeEnum;
import com.ymatou.iapi.optrade.parameter.enums.LogisticsTypeEnum;
import com.ymatou.iapi.optrade.parameter.req.BatchValidateRefundReq;
import com.ymatou.iapi.optrade.parameter.vo.ValidateRefundVo;
import com.ymatou.iapi.optrade.resp.Order;
import com.ymatou.iapi.optrade.resp.TradingServiceResp;
import com.ymatou.iapi.optrade.service.BargainGroupService;
import com.ymatou.iapi.optrade.service.BatchValidateRefundCall;
import com.ymatou.iapi.synctrade.service.TradingSyncService;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.YMTTrading.TradingCallService;
import com.ymttest.business.service.YMTTrading.TradingPlaceOrderCallService;
import com.ymttest.database.sharding.db.sharding.model.OrderDetailPo;
import com.ymttest.database.sharding.db.sharding.model.OrderPo;
import com.ymttest.database.sharding.db.sqlwapper.OrderShardingWapper;
import com.ymttest.database.sqlwapper.DefaultWapper;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.constant.ECode;

/**
 * 退货退款申请效验接口 FreeMaker Template自动生成代码
 */
@TestSuite
@Ignore
public class Ts_BatchValidateRefund {
	private static BatchValidateRefundReq applyvalidationBean;
	private static BatchValidateRefundCall applyvalidationCall;
	
	private static OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
	
	private static long userId = 20238699;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("批量退货退款申请校验接口");
	}

	@Before
	public void caseUp() {
		applyvalidationBean = new BatchValidateRefundReq();
		applyvalidationCall = new BatchValidateRefundCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(applyvalidationCall.getOpurl());
		orderShardingWapper.activeDeadCommunicationsLink(orderShardingWapper);
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_BatchValidateRefund_001() {
		Logger.start(true, "用户下单后申请效验");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService.placeOrderWithCoupon();

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			Logger.comment("前置数据准备结束");

			applyvalidationBean.setOrderId(orderId);

			List<ValidateRefundVo> refundList = Arrays
					.asList(new ValidateRefundVo(placeOrderResp.getOrderList()
							.get(0).getOrderDetailPoList().get(0)
							.getCatalogId(), 1, BigDecimal.ONE));

			applyvalidationBean.setValidateRefundVo(refundList);

			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();

			Logger.verifyEquals(ECode.FAILED201,
					applyvalidationCall.getString("code"), "验证返回码");

			Logger.verifyEquals("114", applyvalidationCall.getString("bcode"),
					"验证返回码");

			Logger.verifyEquals("申请退款金额不能大于实际可退款金额",
					applyvalidationCall.getString("msg"), "验证msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@SuppressWarnings("unchecked")
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_BatchValidateRefund_002() {
		Logger.start(true, "用户支付后接单前效验成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService.payOrder();

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			Logger.comment("前置数据准备结束");

			applyvalidationBean.setOrderId(orderId);

			List<OrderDetailPo> orderInfos = placeOrderResp.getOrderList()
					.get(0).getOrderDetailPoList();

			List<ValidateRefundVo> refundList = Arrays
					.asList(new ValidateRefundVo(orderInfos.get(0)
							.getCatalogId(), 1, BigDecimal.ONE));

			applyvalidationBean.setValidateRefundVo(refundList);

			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();
			Logger.verifyEquals(ECode.SUCCESS,
					applyvalidationCall.getString("code"), "验证返回码");
			Logger.verifyEquals("0", applyvalidationCall.getString("bcode"),
					"验证返回码");

			Map<String, Object> map = applyvalidationCall.getRespMap();

			for (ValidateRefundVo refund : refundList) {

				String catalogId = refund.getCatalogId();

				Logger.comment(String.format("catalogId:%s 退款单校验结果", catalogId));

				Map<String, Object> temp = (Map<String, Object>) map
						.get(catalogId);

				Logger.verifyEquals(false,
						(Boolean) temp.get("isValidationPass"),
						"验证isValidationPass");

				Logger.verifyEquals(true, (Boolean) temp.get("success"),
						"验证success");

			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@SuppressWarnings("unchecked")
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_BatchValidateRefund_004() {
		Logger.start(true, "商家接单后,退货退款校验");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.orderAccept();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			Logger.comment("前置数据准备结束");

			applyvalidationBean.setOrderId(orderId);

			List<ValidateRefundVo> refundList = Arrays
					.asList(new ValidateRefundVo(placeOrderResp.getOrderList()
							.get(0).getOrderDetailPoList().get(0)
							.getCatalogId(), 1, BigDecimal.ONE));

			applyvalidationBean.setValidateRefundVo(refundList);

			applyvalidationCall.setData(applyvalidationBean);

			applyvalidationCall.callService();

			Logger.verifyEquals(ECode.SUCCESS,
					applyvalidationCall.getString("code"), "验证返回码");

			Map<String, Object> map = applyvalidationCall.getRespMap();

			for (ValidateRefundVo refund : refundList) {

				String catalogId = refund.getCatalogId();

				Logger.comment(String.format("catalogId:%s 退款单校验结果", catalogId));

				Map<String, Object> temp = (Map<String, Object>) map
						.get(catalogId);

				Logger.verifyEquals(true, (Boolean) temp.get("success"),
						"验证success");

				Logger.verifyEquals(true,
						(Boolean) temp.get("isValidationPass"),
						"验证isValidationPass");

				Logger.verifyEquals(new Double(0),
						(Double) temp.get("refundFreight"), "验证refundFreight");

			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_BatchValidateRefund_005() {
		Logger.start(true, "商家接单后取消订单,效验成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.orderAccept();

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			long userId = placeOrderResp.getUserId();

			// 取消订单
			TradingCallService.cancelOrder(orderId,
					CancelOrderTypeEnum.CUSTOMER_CANCEL_ORDER, userId);

			Logger.comment("前置数据准备结束");

			applyvalidationBean.setOrderId(orderId);

			List<ValidateRefundVo> refundList = Arrays
					.asList(new ValidateRefundVo(placeOrderResp.getOrderList()
							.get(0).getOrderDetailPoList().get(0)
							.getCatalogId(), 1, BigDecimal.ONE));

			applyvalidationBean.setValidateRefundVo(refundList);

			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();

			Logger.verifyEquals(ECode.FAILED201,
					applyvalidationCall.getString("code"), "验证返回码");

			Logger.verifyEquals("102", applyvalidationCall.getString("bcode"),
					"验证bcode");

			Logger.verifyEquals(String.format("订单已取消，不能退货退款：%s", orderId),
					applyvalidationCall.getString("msg"), "验证msg");

			Logger.verifyEquals(false, applyvalidationCall.getData()
					.getBoolean("success"), "验证success");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@SuppressWarnings("unchecked")
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_BatchValidateRefund_006() {
		Logger.start(false, "订单退货退款中,申请校验的金额小于等于可退款金额");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithThreeProcutInTwoOrder(true, BigDecimal.ZERO,
							userId, LogisticsTypeEnum.OVERSEAS_DELIVERY);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			long userId = placeOrderResp.getUserId();
			long tradingId = placeOrderResp.getTradingId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 付款			
			TradingCallService.payOrder(userId, amount, tradingId);

			// 卖家接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);

			List<OrderDetailPo> orderInfos = placeOrderResp.getOrderList()
					.get(0).getOrderDetailPoList();

			applyvalidationBean.setOrderId(orderId);

			List<ValidateRefundVo> refundList = Arrays.asList(
					new ValidateRefundVo(orderInfos.get(0).getCatalogId(), 1,
							BigDecimal.ONE), new ValidateRefundVo(orderInfos
							.get(1).getCatalogId(), 1, BigDecimal.ONE),
					new ValidateRefundVo(orderInfos.get(2).getCatalogId(), 1,
							BigDecimal.ONE));

			applyvalidationBean.setValidateRefundVo(refundList);

			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();

			Logger.verifyEquals(ECode.SUCCESS,
					applyvalidationCall.getString("code"), "验证返回码");
			Logger.verifyEquals("0", applyvalidationCall.getString("bcode"),
					"验证返回码");
			Map<String, Object> map = applyvalidationCall.getRespMap();

			for (ValidateRefundVo refund : refundList) {

				String catalogId = refund.getCatalogId();

				Logger.comment(String.format("catalogId:%s 退款单校验结果", catalogId));

				Map<String, Object> temp = (Map<String, Object>) map
						.get(catalogId);

				Logger.verifyEquals(true, (Boolean) temp.get("success"),
						"验证success");

				Logger.verifyEquals(true,
						(Boolean) temp.get("isValidationPass"),
						"验证isValidationPass");

				Logger.verifyEquals(new Double(0),
						(Double) temp.get("refundFreight"), "验证refundFreight");

			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@SuppressWarnings("unchecked")
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_BatchValidateRefund_008() {
		Logger.start(true, "用户收货之后申请校验");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.orderConfirmReceive();

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			Logger.comment("前置数据准备结束");
			applyvalidationBean.setOrderId(orderId);

			List<OrderDetailPo> orderInfos = placeOrderResp.getOrderList()
					.get(0).getOrderDetailPoList();

			List<ValidateRefundVo> refundList = Arrays
					.asList(new ValidateRefundVo(orderInfos.get(0)
							.getCatalogId(), 1, BigDecimal.ONE));

			applyvalidationBean.setValidateRefundVo(refundList);

			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();
			Logger.verifyEquals(ECode.SUCCESS,
					applyvalidationCall.getString("code"), "验证返回码");
			Logger.verifyEquals("0", applyvalidationCall.getString("bcode"),
					"验证返回码");

			Map<String, Object> map = applyvalidationCall.getRespMap();

			for (ValidateRefundVo refund : refundList) {

				String catalogId = refund.getCatalogId();

				Logger.comment(String.format("catalogId:%s 退款单校验结果", catalogId));

				Map<String, Object> temp = (Map<String, Object>) map
						.get(catalogId);

				Logger.verifyEquals(true, (Boolean) temp.get("success"),
						"验证success");

				Logger.verifyEquals(true,
						(Boolean) temp.get("isValidationPass"),
						"验证isValidationPass");

				Logger.verifyEquals(new Double(0),
						(Double) temp.get("refundFreight"), "验证refundFreight");

			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_BatchValidateRefund_009() {
		Logger.start(false, "订单号不存在申请效验");
		try {

			applyvalidationBean.setOrderId(11111);

			List<ValidateRefundVo> refundList = Arrays
					.asList(new ValidateRefundVo("sdfsdf", 1, BigDecimal.ONE));

			applyvalidationBean.setValidateRefundVo(refundList);
			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();

			Logger.verifyEquals(ECode.FAILED201,
					applyvalidationCall.getString("code"), "验证返回码");
			Logger.verifyEquals("订单不存在:" + applyvalidationBean.getOrderId(),
					applyvalidationCall.getString("msg"), "验证错误提示");
			Logger.verifyEquals(false, applyvalidationCall.getData()
					.getBoolean("success"), "验证success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_BatchValidateRefund_010() {
		Logger.start(false, "订单号为null申请效验");
		try {
			// applyvalidationBean.setOrderId(111111);

			List<ValidateRefundVo> refundList = Arrays
					.asList(new ValidateRefundVo("sdfsdf", 1, BigDecimal.ONE));

			applyvalidationBean.setValidateRefundVo(refundList);

			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();

			Logger.verifyEquals(ECode.FAILED400,
					applyvalidationCall.getString("code"), "验证返回码");
			Logger.verifyEquals("orderId:订单号不能为空",
					applyvalidationCall.getString("msg"), "验证错误提示");

			Logger.verifyEquals(false, applyvalidationCall.getData()
					.getBoolean("success"), "验证success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@SuppressWarnings("unchecked")
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_BatchValidateRefund_014() {
		Logger.start(true, "商家发货后,退货退款校验");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.orderDelivery();

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			Logger.comment("前置数据准备结束");
			applyvalidationBean.setOrderId(orderId);

			List<OrderDetailPo> orderInfos = placeOrderResp.getOrderList()
					.get(0).getOrderDetailPoList();

			List<ValidateRefundVo> refundList = Arrays
					.asList(new ValidateRefundVo(orderInfos.get(0)
							.getCatalogId(), 1, BigDecimal.ONE));

			applyvalidationBean.setValidateRefundVo(refundList);
			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();
			Logger.verifyEquals(ECode.SUCCESS,
					applyvalidationCall.getString("code"), "验证返回码");
			Logger.verifyEquals("0", applyvalidationCall.getString("bcode"),
					"验证返回码");

			Map<String, Object> map = applyvalidationCall.getRespMap();

			for (ValidateRefundVo refund : refundList) {

				String catalogId = refund.getCatalogId();

				Logger.comment(String.format("catalogId:%s 退款单校验结果", catalogId));

				Map<String, Object> temp = (Map<String, Object>) map
						.get(catalogId);

				Logger.verifyEquals(true, (Boolean) temp.get("success"),
						"验证success");

				Logger.verifyEquals(true,
						(Boolean) temp.get("isValidationPass"),
						"验证isValidationPass");

				Logger.verifyEquals(new Double(0),
						(Double) temp.get("refundFreight"), "验证refundFreight");

			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@SuppressWarnings("unchecked")
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_BatchValidateRefund_015() {
		Logger.start(true, "确认收货15天后,退货退款校验");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.orderConfirmReceive();

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			
			TradingSyncService.getSyncResult(orderId);

			new DefaultWapper().updateOrderConfirmedTimeByOrderId(orderId);

			OrderPo record = new OrderPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.DAY_OF_MONTH, -16);;

			record.setOrderId(orderId);
			record.setReceiveTime(calendar.getTime());

			orderShardingWapper.clearCache();
			orderShardingWapper.orderMapper.updateByPrimaryKeySelective(record);

			Logger.comment("前置数据准备结束");
			applyvalidationBean.setOrderId(orderId);

			List<OrderDetailPo> orderInfos = placeOrderResp.getOrderList()
					.get(0).getOrderDetailPoList();

			List<ValidateRefundVo> refundList = Arrays
					.asList(new ValidateRefundVo(orderInfos.get(0)
							.getCatalogId(), 1, BigDecimal.ONE));

			applyvalidationBean.setValidateRefundVo(refundList);
			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();
			
			TradingSyncService.getSyncResult(orderId);
			
			Logger.verifyEquals(ECode.SUCCESS,
					applyvalidationCall.getString("code"), "验证返回码");
			Logger.verifyEquals("0", applyvalidationCall.getString("bcode"),
					"验证返回码");

			Map<String, Object> map = applyvalidationCall.getRespMap();

			for (ValidateRefundVo refund : refundList) {

				String catalogId = refund.getCatalogId();

				Logger.comment(String.format("catalogId:%s 退款单校验结果", catalogId));

				Map<String, Object> temp = (Map<String, Object>) map
						.get(catalogId);

				Logger.verifyEquals(true, (Boolean) temp.get("success"),
						"验证success");

				Logger.verifyEquals(false,
						(Boolean) temp.get("isValidationPass"),
						"验证isValidationPass");

				Logger.verifyEquals(new Double(0),
						(Double) temp.get("refundFreight"), "验证refundFreight");

			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_BatchValidateRefund_017() {
		Logger.start(true, "商品申请退款金额大于(商品可退金额+订单总运费)");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithThreeProcutInTwoOrder(false, BigDecimal.ZERO,
							userId, LogisticsTypeEnum.OVERSEAS_DELIVERY);

			Order order = placeOrderResp.getOrderList().get(0);

			Long orderId = order.getOrderId();

			//支付
			TradingCallService.payOrder(placeOrderResp.getUserId(),
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getTradingId());
			//接单
			TradingCallService.sellerAcceptOrder(order.getSellerId(), orderId);

			Logger.comment("前置数据准备结束");

			applyvalidationBean.setOrderId(orderId);

			List<OrderDetailPo> orderInfos = placeOrderResp.getOrderList()
					.get(0).getOrderDetailPoList();

			List<ValidateRefundVo> refundList = new ArrayList<ValidateRefundVo>();

			OrderDetailPo po = orderInfos.get(0);

			// 计算订单总价格 商品价格 X 数量+运费
			BigDecimal refoundAmout = po.getProductPrice()
					.multiply(new BigDecimal(po.getProductCount()))
					.subtract(po.getYmtCouponAmount())
					.subtract(po.getSellerCouponAmount())
					.add(order.getOrderFreight().add(new BigDecimal("0.01")));

			ValidateRefundVo vo = new ValidateRefundVo(po.getCatalogId(),
					po.getProductCount(), refoundAmout);

			refundList.add(vo);

			applyvalidationBean.setValidateRefundVo(refundList);

			applyvalidationCall.setData(applyvalidationBean);

			applyvalidationCall.callService();

			Logger.verifyEquals("201", applyvalidationCall.getString("code"),
					"验证返回码");

			Logger.verifyEquals(
					String.format("OrderId:%s, 申请退运费金额不能大于实际可退运费金额", orderId),
					applyvalidationCall.getString("msg"), "验证msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@SuppressWarnings("unchecked")
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_BatchValidateRefund_019() {
		Logger.start(true, "订单商品不是包邮,批量全款加运费退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithThreeProcutInTwoOrder(false, BigDecimal.ZERO,
							userId, LogisticsTypeEnum.OVERSEAS_DELIVERY);

			Order order = placeOrderResp.getOrderList().get(0);

			Long orderId = order.getOrderId();

			//支付
			TradingCallService.payOrder(placeOrderResp.getUserId(),
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getTradingId());
			//接单
			TradingCallService.sellerAcceptOrder(order.getSellerId(), orderId);

			Logger.comment("前置数据准备结束");

			applyvalidationBean.setOrderId(orderId);

			List<OrderDetailPo> orderInfos = placeOrderResp.getOrderList()
					.get(0).getOrderDetailPoList();

			List<ValidateRefundVo> refundList = new ArrayList<ValidateRefundVo>();

			for (int i = 0; i < orderInfos.size(); i++) {

				OrderDetailPo po = orderInfos.get(i);

				// 计算订单总价格 商品价格 X 数量+运费
				BigDecimal refoundAmout = po.getProductPrice()
						.multiply(new BigDecimal(po.getProductCount()))
						.subtract(po.getYmtCouponAmount())
						.subtract(po.getSellerCouponAmount())
						.add(po.getFreight());

				ValidateRefundVo vo = new ValidateRefundVo(po.getCatalogId(),
						po.getProductCount(), refoundAmout);

				refundList.add(vo);

			}

			applyvalidationBean.setValidateRefundVo(refundList);

			applyvalidationCall.setData(applyvalidationBean);

			applyvalidationCall.callService();

			Logger.verifyEquals("200", applyvalidationCall.getString("code"),
					"验证返回码");
			Logger.verifyEquals("null", applyvalidationCall.getString("msg"),
					"验证msg");

			Logger.verifyEquals(ECode.SUCCESS,
					applyvalidationCall.getString("code"), "验证返回码");
			Logger.verifyEquals("0", applyvalidationCall.getString("bcode"),
					"验证返回码");

			Map<String, Object> map = applyvalidationCall.getRespMap();

			for (OrderDetailPo refund : orderInfos) {

				String cataId = refund.getCatalogId();

				Logger.comment(String.format("catalogId:%s 退款单校验结果", cataId));

				Map<String, Object> temp = (Map<String, Object>) map
						.get(cataId);

				Logger.verifyEquals(true, (Boolean) temp.get("success"),
						"验证success");

				Logger.verifyEquals(true,
						(Boolean) temp.get("isValidationPass"),
						"验证isValidationPass");

				DataUtil.verifyDecimalEquals(refund.getFreight(),
						new BigDecimal((Double) temp.get("refundFreight")),
						"验证refundFreight");

			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_BatchValidateRefund_020() {
		Logger.start(true, "退款商品数量大于实际数量");

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.orderAccept();

			Order order = placeOrderResp.getOrderList().get(0);

			long orderId = order.getOrderId();

			Logger.comment("前置数据准备结束");

			applyvalidationBean.setOrderId(orderId);

			List<OrderDetailPo> orderInfos = placeOrderResp.getOrderList()
					.get(0).getOrderDetailPoList();

			List<ValidateRefundVo> refundList = new ArrayList<ValidateRefundVo>();

			for (int i = 0; i < orderInfos.size(); i++) {

				OrderDetailPo po = orderInfos.get(i);

				// 计算订单总价格 商品价格 X 数量+运费
				BigDecimal refoundAmout = po.getProductPrice()
						.multiply(new BigDecimal(po.getProductCount()))
						.subtract(po.getYmtCouponAmount())
						.subtract(po.getSellerCouponAmount())
						.add(po.getFreight());

				ValidateRefundVo vo = new ValidateRefundVo(po.getCatalogId(),
						po.getProductCount() + 1, refoundAmout);

				refundList.add(vo);

			}

			applyvalidationBean.setValidateRefundVo(refundList);

			applyvalidationCall.setData(applyvalidationBean);

			applyvalidationCall.callService();

			Logger.verifyEquals("201", applyvalidationCall.getString("code"),
					"验证返回码code");

			Logger.verifyEquals("114", applyvalidationCall.getString("bcode"),
					"验证返回码bcode");

			Logger.verifyEquals(true, applyvalidationCall.getString("msg")
					.contains("申请退商品数量不能大于实际商品数量"), "验证msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_BatchValidateRefund_026() {
		Logger.start(true, "订单锁定后申请效验");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			TradingServiceResp placeOrderResp = TradingCallService
					.orderAccept();

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			//锁定订单
			TradingCallService.markOrderLock(orderId, 1);

			Logger.comment("前置数据准备结束");

			applyvalidationBean.setOrderId(orderId);

			List<OrderDetailPo> orderInfos = placeOrderResp.getOrderList()
					.get(0).getOrderDetailPoList();

			List<ValidateRefundVo> refundList = Arrays
					.asList(new ValidateRefundVo(orderInfos.get(0)
							.getCatalogId(), 1, BigDecimal.ONE));

			applyvalidationBean.setValidateRefundVo(refundList);

			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();

			Logger.verifyEquals(ECode.FAILED201,
					applyvalidationCall.getString("code"), "验证返回码");

			Logger.verifyEquals("该订单已被客服锁定，暂时无法对该订单进行后续操作",
					applyvalidationCall.getString("msg"), "验证msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_BatchValidateRefund_027() {
		Logger.start(true, "虚拟商品不能发起退货退款");

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = BargainGroupService
					.placeVirtualProduct();

			Order order = placeOrderResp.getOrderList().get(0);

			long orderId = order.getOrderId();

			Logger.comment("前置数据准备结束");

			applyvalidationBean.setOrderId(orderId);

			List<OrderDetailPo> orderInfos = placeOrderResp.getOrderList()
					.get(0).getOrderDetailPoList();

			List<ValidateRefundVo> refundList = Arrays
					.asList(new ValidateRefundVo(orderInfos.get(0)
							.getCatalogId(), 1, BigDecimal.ONE));

			applyvalidationBean.setValidateRefundVo(refundList);

			applyvalidationCall.setData(applyvalidationBean);

			applyvalidationCall.callService();

			Logger.verifyEquals("201", applyvalidationCall.getString("code"),
					"验证返回码");

			Logger.verifyEquals("102", applyvalidationCall.getString("bcode"),
					"验证bcode");
			Logger.verifyEquals("虚拟商品不能发起退货退款",
					applyvalidationCall.getString("msg"), "验证msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_BatchValidateRefund_028() {
		Logger.start(true, "批量退款校验,其中有商品退款金额大于实际可退金额(商品+商品运费)");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithThreeProcutInTwoOrder(false, BigDecimal.ZERO,
							userId, LogisticsTypeEnum.OVERSEAS_DELIVERY);

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			Logger.comment("前置数据准备结束");
			applyvalidationBean.setOrderId(orderId);

			List<OrderDetailPo> orderInfos = placeOrderResp.getOrderList()
					.get(0).getOrderDetailPoList();

			List<ValidateRefundVo> refundList = new ArrayList<ValidateRefundVo>();

			for (int i = 0; i < orderInfos.size(); i++) {

				OrderDetailPo po = orderInfos.get(i);

				BigDecimal refundProFreight = po.getFreight();

				if (i == orderInfos.size() - 1) {

					refundProFreight = refundProFreight.add(new BigDecimal(
							"0.01"));

				}

				// 计算订单总价格 商品价格 X 数量+运费
				BigDecimal refoundAmout = po.getProductPrice()
						.multiply(new BigDecimal(po.getProductCount()))
						.subtract(po.getYmtCouponAmount())
						.subtract(po.getSellerCouponAmount())
						.add(refundProFreight);

				ValidateRefundVo vo = new ValidateRefundVo(po.getCatalogId(),
						po.getProductCount(), refoundAmout);

				refundList.add(vo);

			}

			applyvalidationBean.setValidateRefundVo(refundList);

			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();
			Logger.verifyEquals("201", applyvalidationCall.getString("code"),
					"验证返回码");
			Logger.verifyEquals("114", applyvalidationCall.getString("bcode"),
					"验证返回码");

			Logger.verifyEquals("201", applyvalidationCall.getString("code"),
					"验证返回码");

			Logger.verifyEquals("申请退款金额不能大于实际可退款金额",
					applyvalidationCall.getString("msg"), "验证msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_BatchValidateRefund_029() {
		Logger.start(true, "批量退款校验,其中有商品退款商品数量大于最大可退数量");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithThreeProcutInTwoOrder(false, BigDecimal.ZERO,
							userId, LogisticsTypeEnum.OVERSEAS_DELIVERY);

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			//支付
			TradingCallService.payOrder(placeOrderResp.getUserId(),
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getTradingId());
			//接单
			TradingCallService.sellerAcceptOrder(placeOrderResp.getOrderList()
					.get(0).getSellerId(), orderId);

			Logger.comment("前置数据准备结束");
			applyvalidationBean.setOrderId(orderId);

			List<OrderDetailPo> orderInfos = placeOrderResp.getOrderList()
					.get(0).getOrderDetailPoList();

			List<ValidateRefundVo> refundList = new ArrayList<ValidateRefundVo>();

			for (int i = 0; i < orderInfos.size(); i++) {

				OrderDetailPo po = orderInfos.get(i);

				int refundNum = po.getProductCount();

				if (i == orderInfos.size() - 1) {
					refundNum = refundNum + 1;
				}

				ValidateRefundVo vo = new ValidateRefundVo(po.getCatalogId(),
						refundNum, BigDecimal.ONE);

				refundList.add(vo);

			}

			applyvalidationBean.setValidateRefundVo(refundList);

			applyvalidationCall.setData(applyvalidationBean);
			applyvalidationCall.callService();

			Logger.verifyEquals("114", applyvalidationCall.getString("bcode"),
					"验证返回码");

			Logger.verifyEquals("201", applyvalidationCall.getString("code"),
					"验证返回码");

			Logger.verifyEquals(true, applyvalidationCall.getString("msg")
					.contains("申请退商品数量不能大于实际商品数量"), "验证msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}
